<?php

/**
 * @name ErrorController
 * @desc 错误控制器, 在发生未捕获的异常时刻被调用
 * @see http://www.php.net/manual/en/yaf-dispatcher.catchexception.php
 * @author root
 */
class ErrorController extends \Yaf\Controller_Abstract {
    use \app\library\traits\Json;
	//从2.1开始, errorAction支持直接通过参数获取异常
	public function errorAction($exception) {
		//1. assign to view engine
//        var_dump($exception);
//        var_dump($exception instanceof \app\library\exception\ApiException);
//        var_dump($exception->getMessage());
        if ($exception instanceof \app\library\exception\ApiException) {
//            var_dump("Dasga");
            $this->returnError($exception->getCode(), $exception->getMessage());
            return false;
        } else {
            \app\library\facade\Logger::goRecord('error', 'error', $exception->getMessage());
            $this->getView()->assign("exception", $exception);
        }
		//5. render by Yaf 
	}
}
